package org.example.day02;

/**
 * 第一章节1.8.3:suspend和resume方法的缺点——不同步
 */
public class MyThread3 {
    private String username = "1";
    private String password = "11";
    public void setValue(String u,String p){
        this.username = u;
        if(Thread.currentThread().getName().equals("a")){
            System.out.println("停止a线程！");
            Thread.currentThread().suspend();
        }
        this.password = p;
    }
    public void printUsernameAndPassword(){
        System.out.println(username +"******"+ password);
    }

    public static void main(String[] args) {
        try {
            final MyThread3 m3 = new MyThread3();
            Thread t1 = new Thread(){
                @Override
                public void run() {
                    m3.setValue("a","aa");
                }
            };
            t1.setName("a");
            t1.start();
            Thread.sleep(1000);
            Thread t2 = new Thread(){
                @Override
                public void run() {
                    m3.printUsernameAndPassword();
                }
            };
            t2.start();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
